<template>
  <div class="login-container">
    <div class="login-left">
      <div class="left-background"></div>
      <div class="left-content">
        <h1>企业后台管理系统</h1>
        <p>高效、安全、专业的企业级信息管理解决方案，助力企业数字化转型</p>

        <div class="features">
          <div class="feature">
            <div class="feature-icon">
              <i class="fas fa-shield-alt"></i>
            </div>
            <div class="feature-text">安全可靠</div>
          </div>
          <div class="feature">
            <div class="feature-icon">
              <i class="fas fa-bolt"></i>
            </div>
            <div class="feature-text">高效便捷</div>
          </div>
          <div class="feature">
            <div class="feature-icon">
              <i class="fas fa-chart-line"></i>
            </div>
            <div class="feature-text">数据洞察</div>
          </div>
        </div>
      </div>
    </div>

    <div class="login-right">
      <div class="login-form-container">
        <div class="logo">
          <div class="logo-icon">
            <i class="fas fa-building"></i>
          </div>
          <h2>企业后台管理系统</h2>
          <p>Vue3.x 企业级信息管理系统</p>
        </div>

        <div class="form-title">账号登录</div>

        <el-form
            label-position="top"
            :rules="state.rules"
            :model="state.ruleForm"
            ref="loginFormRef"
            class="login-form"
        >
          <el-form-item label="账号" prop="mobile">
            <el-input
                type="text"
                v-model.trim="state.ruleForm.mobile"
                autocomplete="off"
                placeholder="请输入您的账号"
                size="large"
            >
              <template #prefix>
                <i class="fas fa-user input-icon"></i>
              </template>
            </el-input>
          </el-form-item>

          <el-form-item label="密码" prop="pwd">
            <el-input
                type="password"
                v-model.trim="state.ruleForm.pwd"
                autocomplete="off"
                placeholder="请输入您的密码"
                size="large"
                show-password
            >
              <template #prefix>
                <i class="fas fa-lock input-icon"></i>
              </template>
            </el-input>
          </el-form-item>

          <div class="remember-forgot">
            <el-checkbox v-model="state.checked">记住密码</el-checkbox>
            <a href="#" class="forgot-link">忘记密码?</a>
          </div>

          <el-button
              class="login-button"
              type="primary"
              size="large"
              @click="submitForm"
              :loading="state.loading"
          >
            {{ state.loading ? '登录中...' : '立即登录' }}
          </el-button>

          <div class="login-agreement">
            登录即表示您同意
            <a href="#" class="agreement-link">《服务条款》</a>
            和
            <a href="#" class="agreement-link">《隐私政策》</a>
          </div>
        </el-form>

        <div class="divider">
          <span>其他登录方式</span>
        </div>

        <div class="social-login">
          <div class="social-icon">
            <i class="fab fa-weixin"></i>
          </div>
          <div class="social-icon">
            <i class="fab fa-qq"></i>
          </div>
          <div class="social-icon">
            <i class="fab fa-weibo"></i>
          </div>
        </div>

        <div class="copyright">
          © 2025 企业后台管理系统 | 版权所有
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { localSet } from "../utils/index.js";

const router = useRouter()
const loginFormRef = ref(null)

const state = reactive({
  ruleForm: {
    mobile: 'admin',
    pwd: 'admin'
  },
  checked: true,
  loading: false,
  rules: {
    mobile: [
      { required: true, message: '请输入账号', trigger: 'blur' }
    ],
    pwd: [
      { required: true, message: '请输入密码', trigger: 'blur' },
      { min: 3, message: '密码长度不能少于3位', trigger: 'blur' }
    ]
  }
})

const submitForm = () => {
  if (!loginFormRef.value) return

  loginFormRef.value.validate((valid) => {
    if (valid) {
      state.loading = true
      // 验证账号密码是否为admin
      if (state.ruleForm.mobile === 'admin' && state.ruleForm.pwd === 'admin') {
        // 模拟登录请求延迟
        setTimeout(() => {
          state.loading = false
          // 存储token（可以是任意非空值，这里用固定字符串）
          localSet('token', 'admin_token')
          ElMessage.success('登录成功')
          router.push('/')
        }, 1500)
      } else {
        setTimeout(() => {
          state.loading = false
          ElMessage.error('账号或密码错误，请输入admin')
        }, 1500)
      }
    }
  })
}
</script>

<style scoped>
.login-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.login-left {
  flex: 1;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  position: relative;
  overflow: hidden;
  color: white;
}

.left-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.1;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100"><circle cx="50" cy="50" r="40" stroke="%23ffffff" stroke-width="2" fill="none" /></svg>');
  background-size: 300px;
}

.left-content {
  max-width: 600px;
  z-index: 2;
  text-align: center;
}

.left-content h1 {
  font-size: 36px;
  margin-bottom: 20px;
  font-weight: 600;
}

.left-content p {
  font-size: 18px;
  line-height: 1.6;
  opacity: 0.9;
  margin-bottom: 30px;
}

.features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 30px;
  margin-top: 50px;
}

.feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 160px;
}

.feature-icon {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 15px;
}

.feature-text {
  font-size: 16px;
  text-align: center;
}

.login-right {
  width: 500px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background: white;
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.05);
}

.login-form-container {
  width: 100%;
  max-width: 400px;
}

.logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-icon {
  font-size: 50px;
  color: #1e3c72;
  margin-bottom: 15px;
}

.logo h2 {
  font-size: 28px;
  color: #2c3e50;
  font-weight: 600;
}

.logo p {
  color: #7a7a7a;
  margin-top: 8px;
}

.login-form {
  margin-top: 20px;
}

.form-title {
  font-size: 22px;
  color: #2c3e50;
  margin-bottom: 25px;
  font-weight: 600;
  text-align: center;
}

:deep(.el-form-item) {
  margin-bottom: 25px;
}

:deep(.el-form-item__label) {
  font-weight: 500;
  color: #5a6270;
  margin-bottom: 8px;
  padding: 0;
  font-size: 15px;
}

:deep(.el-input__wrapper) {
  border-radius: 8px;
  padding: 0 15px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  height: 48px;
}

:deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 1px #1e3c72 inset, 0 2px 6px rgba(0, 0, 0, 0.08);
}

.input-icon {
  color: #a0a4ad;
  font-size: 16px;
}

.remember-forgot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

:deep(.el-checkbox__label) {
  color: #5a6270;
}

.forgot-link {
  color: #1e3c72;
  text-decoration: none;
  font-size: 14px;
}

.forgot-link:hover {
  text-decoration: underline;
}

.login-button {
  width: 100%;
  border-radius: 8px;
  height: 48px;
  font-size: 16px;
  font-weight: 600;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  border: none;
  margin-bottom: 20px;
  transition: all 0.3s;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(30, 60, 114, 0.4);
}

.login-agreement {
  text-align: center;
  font-size: 13px;
  color: #7a7a7a;
  margin-bottom: 30px;
}

.agreement-link {
  color: #1e3c72;
  text-decoration: none;
}

.agreement-link:hover {
  text-decoration: underline;
}

.divider {
  display: flex;
  align-items: center;
  margin: 30px 0;
  color: #a0a4ad;
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e6e8eb;
}

.divider::before {
  margin-right: 15px;
}

.divider::after {
  margin-left: 15px;
}

.social-login {
  display: flex;
  justify-content: center;
  gap: 15px;
}

.social-icon {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f7fa;
  color: #5a6270;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s;
  border: 1px solid #e6e8eb;
}

.social-icon:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}

.social-icon:nth-child(1):hover {
  background: #2aae67;
  color: white;
  border-color: #2aae67;
}

.social-icon:nth-child(2):hover {
  background: #12b7f5;
  color: white;
  border-color: #12b7f5;
}

.social-icon:nth-child(3):hover {
  background: #e6162d;
  color: white;
  border-color: #e6162d;
}

.copyright {
  margin-top: 40px;
  text-align: center;
  color: #7a7a7a;
  font-size: 13px;
}

@media (max-width: 992px) {
  .login-container {
    flex-direction: column;
  }

  .login-left {
    display: none;
  }

  .login-right {
    width: 100%;
    padding: 60px 20px;
  }
}
</style>